package cn.com.cjwsjy.monitor.platform.earlywarn.controller;

import cn.com.cjwsjy.monitor.platform.earlywarn.service.EarlyWarningPlanService;
import cn.com.cjwsjy.monitor.platform.earlywarn.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 应急预案管理相关接口
 *
 * @author
 */
@RestController
@RequestMapping("/earlywarn/earlywarningplan")
public class EarlyWarningPlanController {
    @Autowired
    private EarlyWarningPlanService earlyWarningPlanService;


    /**
     * 获取所有工程部位
     * @return
     */
    @GetMapping("/getAllPositions")
    public R getAllPositions() {
        return earlyWarningPlanService.getAllPositions();
    }

    /**
     * 添加应急预案
     * @return
     */
    @PostMapping("/addPlan")
    public R addPlan(@RequestParam("docName") String docName, @RequestParam("warningLevel") String warningLevel,
                     @RequestParam("applicablePeriod") String applicablePeriod, @RequestParam("positionName") String positionName,
                     @RequestParam("file") MultipartFile file,@RequestParam("uploadPerson") String uploadPerson) throws IOException {
        return earlyWarningPlanService.addPlan(docName,warningLevel,applicablePeriod,positionName,file,uploadPerson);
    }
    /**
     * 获取所有可适用时期
     * @return 可适用时期列表
     */
    @GetMapping("/getAllPeriods")
    public R getAllPeriods(){
        return  earlyWarningPlanService.getAllPeriods();
    }
    /**
     * 修改应急预案
     * @return
     */
    @PostMapping("/updatePlan")
    public R updatePlan(@RequestParam("id") Long id, @RequestParam("docName") String docName, @RequestParam("warningLevel") String warningLevel,
                        @RequestParam("applicablePeriod") String applicablePeriod, @RequestParam("positionName") String positionName,
                        @RequestParam("file") MultipartFile file,@RequestParam("uploadPerson") String uploadPerson) throws IOException {
        return earlyWarningPlanService.updatePlan(id,docName,warningLevel,applicablePeriod,positionName,file,uploadPerson);
    }
    /**
     * 删除应急预案
     * @return
     */
    @GetMapping("/deletePlan/{id}")
    public R deletePlan(@PathVariable Long id){
        return  earlyWarningPlanService.deletePlan(id);
    }

}
